<template>
  <div class="blogArticleList">
    <el-container style="overflow:auto">
      <el-main style="width: 75%">
        <div class="infinite-list-wrapper" style="padding-top: 1%">
          <div
            class="list"
            v-infinite-scroll="load"
            infinite-scroll-immediate="true"
            infinite-scroll-disabled="disabled">
            <div v-for="i in count" class="list-item" :key="i">
              <articlePreview :msg="articleList[i]"/>
            </div>
          </div>
          <p class="tip" v-if="loading">加载中...</p>
          <p class="tip" v-if="noMore">没有更多了</p>
        </div>
      </el-main>
      <el-aside style="width: 25%">
        <navigation/>
      </el-aside>
    </el-container>
  </div>
</template>

<script>
import articlePreview from './articlePreview'
import navigation from '../navigation/navigation'

export default {
  name: 'blogArticleList',
  data () {
    return {
      count: this.articleList.length,
      loading: false,
      articleList: []
    }
  },
  computed: {
    noMore () {
      return this.count >= 20
    },
    disabled () {
      return this.loading || this.noMore
    }
  },
  created () {
    this.$axios.post(
      {
        method: 'POST',
        url: '',
        data: {}
      },
    ).then(res => {
      if (res.code !== 0) {
        alert(res.msg)
      } else {
        this.articleList = res.data
      }
    }).catch(err => {
      console.log(err)
    })
    // todo 获取文章列表
  },
  methods: {
    load () {
      this.loading = true
      setTimeout(() => {
        this.count += 2
        this.loading = false
      }, 2000)
    }
  },
  components: {articlePreview, navigation}
}
</script>

<style scoped>
  * {
    margin: 0;
    padding: 0;
  }

  .list-item {
    margin-left: 9%;
    margin-right: 5%;
    margin-bottom: 3%;
  }

  .tip {
    margin-left: 20%;
    margin-right: 11%;
  }

  /*TODO 删除*/
  .el-aside {
    background-color: #1989fa;
  }
</style>
